package com.css.fxfzaqbz.modules.assess1.controller;

import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.assess1.entity.AlgEntity;
import com.css.fxfzaqbz.modules.assess1.entity.AlgVO;
import com.css.fxfzaqbz.modules.assess1.service.DestoryAlgService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author y1fan
 * @create 2022-12-01 14:08
 * 人口伤亡评估算法
 */
@RestController
@RequestMapping("/fxfzaqbz/DestoryRate")
@Slf4j
public class DestoryAlgController {


    @Resource
    DestoryAlgService destoryAlgService;


    /*
    *
    * 算法的保存数据
    * */
    @PostMapping("/alg")
    public RestResponse alg(@RequestBody AlgVO algVO){
        RestResponse restResponse = null;
        try{
            restResponse =destoryAlgService.alg(algVO);
           return  restResponse;
        }catch (Exception e){
            String errormessage = e.getMessage();
            if(StringUtils.isBlank(errormessage)) {
                errormessage = "保存失败";
            }
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /*
    算法的查询数据接口
    * */
    @GetMapping("/getAlg")
    public RestResponse getAlg(@RequestBody AlgVO algVO){
        RestResponse restResponse = null;
        try{
            List<AlgEntity> algEntityList=destoryAlgService.getAlg(algVO);
            restResponse = RestResponse.succeed(algEntityList);
        }catch (Exception e){
            String errormessage = e.getMessage();
            if(StringUtils.isBlank(errormessage)) {
                errormessage = "查询失败";
            }
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    @GetMapping("/updateAlg")
    public RestResponse updateAlg(List<AlgEntity> algEntityList){
        RestResponse restResponse = null;
        try{

          destoryAlgService.updateAlg(algEntityList);
            restResponse = RestResponse.succeed("修改完成");
        }catch (Exception e){
            String errormessage = e.getMessage();
            if(StringUtils.isBlank(errormessage)) {
                errormessage = "修改失败";
            }
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }



   /* @Resource
    private RestTemplateUtil restTemplateUtil;
    @GetMapping("/test")
    public String test(){
        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String poUrl = configGroup.getProperty("restTemplateUrl") + "/datacenter/jcBoua2/page";
        Map<String, Object> paramMap = new HashMap<>();
        ResponseEntity<String> cchResponseEntity = restTemplateUtil.sendHttpRequest(poUrl, paramMap);
        return cchResponseEntity.getBody();
    }*/



}
